package org.example.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MethodProxy implements InvocationHandler {
    Object target;
    public MethodProxy(Object target) {
        this.target = target;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if(Object.class.equals(method.getDeclaringClass())) {
            System.out.println("object method");
            return method.invoke(this, args);
        }
        System.out.println("代理增强");
        return method.invoke(target, args);
    }
}
